<?php

/**
 * Contains a collection of references to other objects.
 *
 */
class Junction_Mapping_References implements IteratorAggregate {
	
	private $_references;
	
	public function __construct() {
		$this->_references = array();
	}
	
	/**
	 * @param String $property
	 * @return boolean
	 */
	public function contains($property) {
		return (isset($this->_references[$property]));
	}
	
	/**
	 * @return Iterator over the reference properties 
	 */
	public function getIterator() {
		return new ArrayIterator($this->_references);
	}
	
	/**
	 * @return Iterator
	 */
	public function getProperties() {
		return new ArrayIterator(array_keys($this->_references));
	}
	
	/**
	 * @param String $property
	 * @return Junction_Mapping_DirectReference
	 */
	public function propertyToReference($property) {
		if ($this->contains($property)) {
			return $this->_references[$property];
		}
		return null;
	}
	
	/**
	 * @param String $property
	 * @param Junction_Mapping_DirectReference $reference
	 */
	public function addReference($property, $reference) {
		$this->_references[$property] = $reference;
	}
}
?>